<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../includes/common.jsp" %>

<form action="${scriptPath}">

    <input type="hidden" name="action" value="mark.editchoices"></input>
    <input type="hidden" name="mi_mark" value="${param.mi_mark}"></input>
    <input type="hidden" name="mode" value="${param.mode}"></input>
    
	<p>Sinh viên: <b>${action.mark.studentSurname} ${action.mark.studentName}</b></p>
	<c:if test="${not empty action.mark.studentId}">
	    <p>MSSV: <b>${action.mark.studentId}</b></p>
	</c:if>
	<c:if test="${not empty action.mark.studentBirthday}">
	    <p>Ngày sinh: <b>${u:formatDate(action.mark.studentBirthday)}</b></p>
	</c:if>
	
	<c:set var="type" value='${action.test.type=="radio" ? "radio" : "checkbox"}'></c:set>
	<table class="mark-question-list">
	    <c:set var="i" value="0"></c:set>
	    <c:forEach items="${action.test.sections}" var="section">
	       
	       <c:set var="questionIds" value="${action.version.data.questionsOrder[section.id]}"></c:set>
	       <c:forEach items="${questionIds}" var="questionId">
	            <c:set var="question" value="${section.questionById[questionId]}"></c:set>
	            <tr onmouseover="this.removeClassName('mouse-out'); this.addClassName('mouse-in');" 
		                onmouseout="this.removeClassName('mouse-in'); this.addClassName('mouse-out');">     
		            <td>
		                <b>Câu ${i+1}</b>
		            </td>           
		                
		            <c:set var="j" value="0" />
	                <c:set var="answerIds" value="${action.version.data.answersOrder[section.id][questionId]}"></c:set>
	
	                <c:forEach items="${answerIds}" var="answerId">
	                    <c:set var="answer" value="${question.answerById[answerId]}"></c:set>

		               <c:set var="choosed" scope="page" value="${false}"></c:set>
		               <c:forEach items="${action.mark.choices[question.id]}" var="choice">
		                     <c:if test="${choice == answer.id}">
		                           <c:set var="choosed" scope="page" value="${true}"></c:set>
		                     </c:if>
		               </c:forEach>

	                    <td>
	                        <label style="display: block; width: 100%;">
	                            <input type="${type}" ${choosed ? 'checked="checked"' : ''} 
	                                   name="mi_q${question.id}" value="${answer.id}"></input>
	                            <b>${u:alpha(j)}</b>
	                            <c:set var="j" value="${j+1}" />
	                        </label>
	                    </td>
	                </c:forEach>
		            <c:set var="i" value="${i+1}"></c:set>
	            </tr>   
	       </c:forEach>
	    
	    </c:forEach>
	</table>
	
	<c:if test="${param.mode == 'create'}">
	   <label><input type="checkbox" name="more" value="more" 
	           ${param.more=='more' ? 'checked="checked"' : ''}></input>Thêm nữa</label>
	</c:if>
	
	<button type="submit" name="mi_submit" value="save">Lưu</button>
	<button type="button" onclick="location.href='${scriptPath}?action=mark.view&mv_id=${action.mark.id}'">Quay về bài làm</button>
</form>